package base.DynamicAgentExtension;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 功能:
 * 作者: 洪世成
 * 日期: 2017/11/2
 * 版权所有: admin
 */
public class InjectBeanSelfProcessor implements BeanPostProcessor
{

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
    {
        if(bean instanceof BeanSelfAware)
        {
            System.out.println("inject proxy：" + bean.getClass());
            BeanSelfAware myBean = (BeanSelfAware)bean;
            myBean.setSelf(bean);
            return myBean;
        }
        return bean;
    }

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
    {
        return bean;
    }
}